/*
 * CS_REQ_COSTUME_INFO_BY_ID.cpp
 *
 *  Created on: 2013. 10. 22.
 *      Author: mega@gamevil.com
 */

#include "../../Command.h"

#include "../../User.h"
#include "../../Proxy.h"
#include "../../NLogic/Space.h"
#include "../../NLogic/Equip.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_REQ_COSTUME_INFO_BY_ID(User * pUser, ::Network::Packet * pPacket)
{
/*	/// 코스튬 정보 요청(ui에서 사용될)
 *  이 패킷은 PVP AI 대전에서만 사용한다.
 *
	CS_REQ_COSTUME_INFO_BY_SLOT_SEQ 	0x030E
	{
		u32	userseq;				//캐릭터 고유 DB인덱스
	}

	SC_REQ_COSTUME_INFO		0x030D
	{
		u32 u32gid;
		u8 u8costume_head;
		u8 u8costume_armor;
		u8 u8costume_weapon;
		u8 u8costume_side_hand;
		u8 u8costume_effectt;
		u8 u8costume_vehicle;
	}
	*/

	PREPARE_PACKET;

	int oppUserSeq	= 0;

	*pPacket >> oppUserSeq;

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CS_REQ_COSTUME_INFO_BY_ID : pSpace is NULL");
		return;
	}

	User * pDummy = NULL;

	if (true == pSpace->GetData()._bPVPDummyUser)
	{
		pDummy = NResource::Static::InstancePtr()->GetDummyUserResource()->GetDummyUser(pSpace->GetData()._PVPDummyUserSeq);

		if (NULL == pDummy)
		{
			DEBUGLOG("CS_REQ_COSTUME_INFO_BY_ID : NULL == pDummy");
			return;
		}
	}
	else
	{
		auto iter = ::ProjectZ::NProxy::GetUserTree().find(oppUserSeq);

		if (iter == ::ProjectZ::NProxy::GetUserTree().end())
		{
			DEBUGLOG("CS_REQ_COSTUME_INFO_BY_ID : iter == GetUserTree().end()");
			return;
		}

		pDummy	= iter->second;
	}

	NLogic::Equip * pEquip = pDummy->GetEquip();
	if (NULL == pEquip)
	{
		DEBUGLOG("CS_REQ_COSTUME_INFO_BY_ID : pEquip is NULL!!!");
		return;
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	*pAck << oppUserSeq;

	// 아바타를 장착한 경우
	if (true == pEquip->IsExistItem(ITEM_EQUIP_POS_AVARTAR))
	{
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
	}
	else
	{
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_HELMET));
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_ARMOR));
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_WEAPON));
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_WEAPON));
	}

	*pAck << static_cast<uint8_t>(0);
	*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_VEHICLE));

	pAck->MakePacket(CMD_SC_REQ_COSTUME_INFO);

	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/
